//package com.abl.common.ws.handler;
//
//import io.netty.channel.Channel;
//import io.netty.channel.ChannelHandler;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.ChannelInboundHandlerAdapter;
//import io.netty.handler.timeout.IdleStateEvent;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.Enumeration;
//import java.util.Iterator;
//
//@Slf4j
//@Component
//@ChannelHandler.Sharable
//public class MyIdleStateHandler extends ChannelInboundHandlerAdapter {
//
//    @Override
//    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
//        if (evt instanceof IdleStateEvent event) {
//            String eventType = switch (event.state()) {
//                case READER_IDLE -> "读空闲";
//                case WRITER_IDLE -> "写空闲";
//                case ALL_IDLE -> "读写空闲";
//            };
//
//            //每隔5分钟清理断开的连接，释放内存
////            Enumeration<String> keys = TextHandler.channelAll.keys();
////            Iterator<String> iterator = keys.asIterator();
////            while (iterator.hasNext()) {
////                String channelKey = iterator.next();
////                Channel channel = TextHandler.channelAll.get(channelKey);
////                if (!channel.isOpen()) {
////                    TextHandler.channelAll.remove(channelKey);
////                }
////            }
//
//            System.out.println(ctx.channel().remoteAddress() + "超时事件：" + eventType);
//            ctx.channel().close();
//        } else {
//            super.userEventTriggered(ctx, evt);
//        }
//    }
//}